import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/ok1") //必须要有/否则无效，在这里报错过好多次，不长记性
public class OkServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("注解OkServlet doGet 被调用");

        //1.通过response 获取流 PrintWriter ,可以给浏览器回复数据
        //2.为了让浏览器显示中文，需要告诉浏览器，我们的编码是utf-8，
        // 必须要写，而且要写在发送数据之前，浏览器数据否则乱码
        //下面这段代码每个网址输出个性需求可能不一样，就不封装了
        response.setContentType("text/html;charset=utf-8");

        PrintWriter writer = response.getWriter();
        writer.println("登陆成功~~<ok1>");
        writer.close();
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("注解OkServlet doPost 被调用");
    }
}
